package com.soft.util.demo;

import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import java.io.IOException;
public class MySAXApp {
  public static void main( String[] args ) {
    
//    if ( args.length != 1 ) {
//      System.out.println("输入: java MySAXApp ");
//      System.exit(0);
//    }
    try {
        // 初始化reader
        XMLReader reader = XMLReaderFactory.createXMLReader
                          ("org.apache.xerces.parsers.SAXParser") ;
        // 创建ContentHandler的实例
        ContentHandler contentHandler = new MyContentHandler();
        // 在reader中注册实例化的ContentHandler
        reader.setContentHandler( contentHandler );
        String fileName = "ibm_sax_demo.xml";
        // 开始解析文档
        //reader.parse(args[0]);
        reader.parse(fileName);
    } catch ( IOException e ) {
        System.out.println("读入文档时错: " + e.getMessage());
    } catch ( SAXException e ) {
        System.out.println("解析文档时错: " + e.getMessage());
    }
  }
}
